<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .hour {
            float: left;
            font-size: 15px;
            text-align: center;
            line-height: 30px;
            width: 30px;
            height: 30px;
            color: #ffffff;
            background-color: black;
        }

        .minute {
            float: left;
            margin-left: 5px;
            font-size: 15px;
            text-align: center;
            line-height: 30px;
            width: 30px;
            height: 30px;
            color: #ffffff;
            background-color: black;
        }

        .second {
            float: left;
            margin-left: 5px;
            font-size: 15px;
            text-align: center;
            line-height: 30px;
            width: 30px;
            height: 30px;
            color: #ffffff;
            background-color: black;
        }
    </style>
</head>

<body>
    <div>
        <span class="hour"></span>
        <span class="minute"></span>
        <span class="second"></span>
    </div>

    <script>
        var hour = document.querySelector('.hour')
        var hominuteur = document.querySelector('.minute')
        var second = document.querySelector('.second')
        var usertime = +new Date('2021-1-11 19:30:00');    //用户输入的时间
        // 开启定时器
        setInterval(Datatime, 1000)

        function Datatime() {
            var gettime = +new Date();   //获取当前时间毫
            //然后 用户输入时间 - 当前时间毫 =要倒计时时间毫 / 1000  转换为秒数
            var dwotime = (usertime - gettime) / 1000;
            var h = parseInt(dwotime / 60 / 60 % 24);
            var h = h < 10 ? '0' + h : h;
            hour.innerHTML = h;                 //把剩余的小时给盒子

            var m = parseInt(dwotime / 60 % 60);
            var m = m < 10 ? '0' + m : m;
            hominuteur.innerHTML = m;

            var s = parseInt(dwotime % 60);
            var s = s < 10 ? '0' + s : s;
            second.innerHTML = s;
        }
          //d = parseInt(总秒数/60/60/24);    计算天数、
        //h = parseInt(总秒数/60/60%24);    计算小时
        //m = parseInt(总秒数/60 %60);      计算分数
        //s = parseInt(总秒数%60);          计算当前秒数
    </script>
</body>

</html>